﻿Public Class Environment

    'Construct:
    Public Shared Sub _construct(ByVal command As String, ByVal dir As String)
        Dim commandArray() As String = command.Split(" ")
        Select Case commandArray(0)
            Case Is = "shutdown"
                Call shutdown(command)
            Case Is = "reboot"
                Call restart(command)
            Case Is = "logoff"
                Call logoff(command)
        End Select
    End Sub

    Public Shared Function shutdown(ByVal command As String)
        Dim commandArray() As String = command.Split(" ")
        If UBound(commandArray) = 1 Then
            Select Case commandArray(1).Substring(0, 3)
                Case Is = "-t="
                    Dim time As Integer = CInt(commandArray(1).Remove(0, 3))
                    Shell("shutdown.exe /s /t " & time)
            End Select
        Else
            Shell("shutdown.exe /s /f")
        End If
    End Function

    Public Shared Function restart(ByVal command As String)
        Dim commandArray() As String = command.Split(" ")
        If UBound(commandArray) = 1 Then
            Select Case commandArray(1).Substring(0, 3)
                Case Is = "-t="
                    Dim time As Integer = CInt(commandArray(1).Remove(0, 3))
                    Shell("shutdown.exe /r /t " & time)
            End Select
        Else
            Shell("shutdown.exe /r /f")
        End If
    End Function

    Public Shared Function logoff(ByVal command As String)
        Dim commandArray() As String = command.Split(" ")
        If UBound(commandArray) = 1 Then
            Select Case commandArray(1).Substring(0, 3)
                Case Is = "-t="
                    Dim time As Integer = CInt(commandArray(1).Remove(0, 3))
                    Shell("shutdown.exe /l /t " & time)
            End Select
        Else
            Shell("shutdown.exe /l /f")
        End If
    End Function
End Class
